# Maintainer: Renato Silva <br.renatosilva@gmail.com>

_realname='libsignal-protocol-c'
pkgbase="mingw-w64-${_realname}-git"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r34.16bfd04
pkgrel=1
pkgdesc='Signal Protocol C Library (mingw-w64)'
url='https://github.com/WhisperSystems/libsignal-protocol-c'
license=(GPL3)
arch=('any')

options=(!libtool strip staticlibs)
source=('git+https://github.com/WhisperSystems/libsignal-protocol-c')
sha256sums=('SKIP')
conflicts=(${MINGW_PACKAGE_PREFIX}-${_realname})
provides=(${MINGW_PACKAGE_PREFIX}-${_realname})
makedepends=(${MINGW_PACKAGE_PREFIX}-gcc
             ${MINGW_PACKAGE_PREFIX}-cmake
             rsync git)

pkgver() {
    cd "${srcdir}/${_realname}"
    printf "r%s.%s" $(git rev-list --count HEAD) $(git rev-parse --short HEAD)
}

build() {
    msg2 'Synchronizing build directory'
    rsync --recursive --times "${srcdir}/${_realname}"/* "${srcdir}/${_realname}.build.${CARCH}"
    cd "${srcdir}/${_realname}.build.${CARCH}"
    cmake -G'MSYS Makefiles' -DCMAKE_INSTALL_PREFIX=/${MINGW_PREFIX} ../${_realname}
    make
}

package() {
    cd "${srcdir}/${_realname}.build.${CARCH}"
    make DESTDIR="${pkgdir}" install
    install -Dm644 "${srcdir}/${_realname}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
